package com.xonro.common.histrans.sfeg.job.update;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.schedule.IJob;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;
import com.xonro.common.histrans.base.consts.SfegConst;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.util.List;

public class UpdateCustomerbank implements IJob {


    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        List<RowMap> maps = DBSql.getMaps("SELECT ID,COMPANY_NO,BINDID  FROM BO_XR_MDM_CUSTOMER  ");

        for(RowMap m:maps){
            String companyNo=m.getString("COMPANY_NO");
            String id=m.getString("ID");
            String bindid=m.getString("BINDID");
            RowMap mainMap = SDK.getCCAPI().getRDSAPI(SfegConst.CCID).getMap("SELECT BankName,BankAccount,khmc FROM tb_khxx  WHERE khbh = '" + companyNo + "'  ");
            if(null==mainMap){
                continue;
            }
            String khmc=mainMap.getString("khmc");
            String bankName=mainMap.getString("BankName");
            String bankAccount=mainMap.getString("BankAccount");
            DBSql.update("UPDATE BO_XR_MDM_CUSTOMER SET RECIPIENT_BANK_NAME='"+bankName+"',BANK_NAME='"+bankName+"',BANK_ACCOUNT='"+bankAccount+"' WHERE ID='"+id+"'"  );
            BO bo=new BO();
            bo.set("ACCOUNT_NAME",khmc);
            bo.set("BANK_NAME",bankName);
            bo.set("BANK_ACCOUNT",bankAccount);
            bo.set("STATUS","1");
            SDK.getBOAPI().create("BO_XR_MDM_CUSTOMER_BANK",bo,bindid,"admin");
        }

    }


}
